﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Environment;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Protocol;

namespace Pixysoft.Weblications.Sango.Command.player
{
    partial class SangoPlayerHandler
    {
        public player_allowance player_allowance()
        {
            string userCode = SangoManager.Authentication();

            player_allowance response = ReflectionManager.CreatePojo<player_allowance>();
            response.Succeed = false;

            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);
            Entities.Usr_Property property = UsrPropertyDao.getProperty(userCode);
            Entities.Usr_Activity activity = UsrActivityDao.getHistory(userCode);

            if (activity.Allowancecount > 0)
            {
                response.Message = "今天已经领取了俸禄";
                return response;
            }


            Entities.Sys_Famesetting famesetting = SysFameSettingHelper.getFrame(property.Fametitletypecode);
            long cashvalue = famesetting.Allowancevalue;
            if (!UsrProfileDao.tryIncreaseCashvalue(profile, cashvalue))
            {
                response.Message = "银币达到上线，无法领取。";
                return response;
            }

            activity.Allowancecount = (activity.Allowancecount + 1);

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;
            command.Begin(delegate()
            {
                command.Update(activity);

                command.Update(profile);

                command.Commit();

            });

            response.cash = cashvalue;
            response.profile = UsrProfileFacade.ToProfile(profile);
            response.Succeed = true;
            return response;
        }


    }
    public interface player_allowance : ISangoResponse
    {
        long cash { get;set;}

        player_profile profile { get;set;}
    }
}
